package ar.com.spsolutions.splibrary.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class ResourcesUtil {
    public static class ResourceUtilException extends RuntimeException {

        private static final long serialVersionUID = 9165868248683071470L;

        public ResourceUtilException(final Throwable cause) {
            super(cause);
        }

    }

    public static File findResource(final String relativePath) {
        String relative = new File(".").getAbsolutePath() + "/src/main/resources/";
        String absolute = relative + relativePath;
        return new File(absolute);
    }

    private ResourcesUtil() {

    }

    public static InputStream findResourceAsStream(final String relativePath) {
        try {
            File findResource = findResource(relativePath);
            return new FileInputStream(findResource);
        } catch (FileNotFoundException e) {
            throw new ResourceUtilException(e);
        }
    }
}
